
package com.platform.modules.mall.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.platform.common.annotation.SysLog;
import com.platform.common.utils.Constant;
import com.platform.common.utils.RestResponse;
import com.platform.modules.mall.entity.MallPrizeEntity;
import com.platform.modules.mall.service.MallPrizeService;
import com.platform.modules.sys.controller.AbstractController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 奖品表Controller
 *
 * @author 
 * @date 2021-05-26 08:39:03
 */
@RestController
@RequestMapping("mall/prize")
public class MallPrizeController extends AbstractController {
    @Autowired
    private MallPrizeService mallPrizeService;

    /**
     * 查看所有列表
     *
     * @param params 查询参数
     * @return RestResponse
     */
    @RequestMapping("/queryAll")
    @RequiresPermissions("mall:prize:list")
    public RestResponse queryAll(@RequestParam Map<String, Object> params) {
        List<MallPrizeEntity> list = mallPrizeService.queryAll(params);

        return RestResponse.success().put("list", list);
    }

    /**
     * 分页查询奖品表
     *
     * @param params 查询参数
     * @return RestResponse
     */
    @GetMapping("/list")
    @RequiresPermissions("mall:prize:list")
    public RestResponse list(@RequestParam Map<String, Object> params) {
        Page page = mallPrizeService.queryPage(params);

        return RestResponse.success().put("page", page);
    }

    /**
     * 根据主键查询详情
     *
     * @param prizeId 主键
     * @return RestResponse
     */
    @RequestMapping("/info/{prizeId}")
    @RequiresPermissions("mall:prize:info")
    public RestResponse info(@PathVariable("prizeId") String prizeId) {
        MallPrizeEntity mallPrize = mallPrizeService.getById(prizeId);

        return RestResponse.success().put("prize", mallPrize);
    }

    /**
     * 新增奖品表
     *
     * @param entity mallPrize
     * @return RestResponse
     */
    @SysLog("新增奖品表")
    @RequestMapping("/save")
    @RequiresPermissions("mall:prize:save")
    public RestResponse save(@RequestBody MallPrizeEntity entity) {
        entity.setAddTime(new Date());
        entity.setUserId(getUserId());
        if(entity.getCategoryId().equals(Constant.STR_NINE)){
            entity.setCategoryName("九宫格");
        }else {
            entity.setCategoryName("转盘");
        }
        mallPrizeService.add(entity);
        return RestResponse.success();
    }

    /**
     * 修改奖品表
     *
     * @param mallPrize mallPrize
     * @return RestResponse
     */
    @SysLog("修改奖品表")
    @RequestMapping("/update")
    @RequiresPermissions("mall:prize:update")
    public RestResponse update(@RequestBody MallPrizeEntity mallPrize) {
        mallPrize.setModifyTime(new Date());
        mallPrize.setUserId(getUserId());
        if(mallPrize.getCategoryId().equals(Constant.STR_NINE)){
            mallPrize.setCategoryName("九宫格");
        }else {
            mallPrize.setCategoryName("转盘");
        }
        mallPrizeService.update(mallPrize);
        return RestResponse.success();
    }

    /**
     * 根据主键删除奖品表
     *
     * @param prizeIds prizeIds
     * @return RestResponse
     */
    @SysLog("删除奖品表")
    @RequestMapping("/delete")
    @RequiresPermissions("mall:prize:delete")
    public RestResponse delete(@RequestBody String[] prizeIds) {
        mallPrizeService.deleteBatch(prizeIds);
        return RestResponse.success();
    }
}
